//
//  CTMediator+ViewAction.m
//  at_xiaoge_client
//
//  Created by Linyu Niu on 15/03/2018.
//  Copyright © 2018 Linyu Niu. All rights reserved.
//

#import "CTMediator+ViewAction.h"



NSString * const  kCTMediatorUtilityViewTarget                                              = @"UtilityView";
NSString * const  kCTMediatorNavigationHeadViewAction                                       = @"navigationHeadView";
NSString * const  kCTMediatorCommonOrangeButtonAction                                       = @"commonOrangeButton";
NSString * const  kCTMediatorShowBankTypePickerAction                                       = @"showBankTypePicker";

@implementation CTMediator(ViewAction)



-(UIButton *)commonOrangeButton:(CGRect)frame title:(NSString *)title delegate:(id)delegate action:(SEL)action{
    NSMutableDictionary * dic = [NSMutableDictionary dictionary];
    [dic setNLYObjectForKey:title forKey:@"title"];
    [dic setNLYObjectForKey:delegate forKey:@"delegate"];
    [dic setObject:NSStringFromCGRect(frame) forKey:@"frame"];
    if (action) {
        NSString * name  = [NSString stringWithUTF8String:sel_getName(action)];
        [dic setObject:name forKey:@"action"];
    }
    return [self  performTarget:kCTMediatorUtilityViewTarget action:kCTMediatorCommonOrangeButtonAction params:dic shouldCacheTarget:NO];
    
}
-(UIView *)navgationHeadViewInTargetView:(UIView *)view params:(NSDictionary *)dic leftAction:(void(^)(UIButton * sender))leftAction rightAction:(void(^)(UIButton * sender))rightAction{
    NSMutableDictionary * params = [NSMutableDictionary dictionary];
    if ([dic count]) {
        [params addEntriesFromDictionary:dic];
    }
    if (leftAction) {
        [params setObject:leftAction forKey:@"leftAction"];
    }
    if (rightAction) {
        [params setObject:rightAction forKey:@"rightAction"];
    }
    UIView * v = (UIView *)[self performTarget:kCTMediatorUtilityViewTarget action:kCTMediatorNavigationHeadViewAction params:params shouldCacheTarget:NO];
    [view addSubview:v];
    return v;
}



-(void)showBankTypePicker:(UIView *)view delegate:(id<UIPickerViewDataSource,UIPickerViewDelegate>)delegate block:(void(^)(void))block{
    NSMutableDictionary * dic = [NSMutableDictionary dictionary];
    if (view) {
        [dic setObject:view forKey:@"view"];
    }
    if (delegate) {
        [dic setObject:delegate forKey:@"delegate"];
    }
    if (block) {
        [dic setObject:block forKey:@"action"];
    }
    [self performTarget:kCTMediatorUtilityViewTarget action:kCTMediatorShowBankTypePickerAction params:dic shouldCacheTarget:NO];
}
@end
